<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>$emit 和 $on</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="root">
    <button @click="boost">触发事件</button>
</div>
<script>
    new Vue({
        el: '#root',
        data() {
            return {
                message: 'hello vue'
            }
        },
        created() {
            this.$on('my_events', this.handleEvents)
        },
        methods: {
            handleEvents(e) {
                console.log(this.message, e)
            },
            boost() {
                this.$emit('my_events', 'my params')
            }
        }
    })
</script>
</body>
</html>